define([
  'utils/Conf',
  'models/Model'
], function(Conf, Model){  
  var Message = Model.extend({
    initialize: function(attrs) {
      if(attrs && attrs.type == "inbox") {
        this.inbox = true;
      } else {
        this.inbox = false;
      }
      Model.prototype.initialize.call(this, attrs);
      // Listen to remove event that will be fired from a collection when the element is removed.
      //this.bind("remove", this.destroy, this);
      // Selection
      var selected = false;
      this.setSelected = function(selection) {
        selected = selection;
        if(selection) {
          this.trigger("selected");
          if(this.collection) {
            this.collection.trigger("item:selected");
          }
        } else {
          this.trigger("unselected");
          if(this.collection) {
            this.collection.trigger("item:unselected");
          }
        }
      };
      this.getSelected = function() {
        return selected;
      };
    },
    
    url: function() {
      if(this.inbox || (this.collection && this.collection.inbox)) {
        var urlBase = Conf.routes.messages.inbox;
      } else {
        var urlBase = Conf.routes.messages.outbox;
      }

      if(this.id) {
        urlBase += "/" + this.id;
      }
      return urlBase;
    },

    save: function(attrs, options) {
      options || (options = {});
      if(!this.id) {
        options.url = Conf.routes.messages.share;
      }
      Model.prototype.save.call(this, attrs, options);
    }
  });

  return Message;
});